import { Spin } from "antd";
import { data } from "jquery";
import React, {
    useState,
    useCallback,
    useEffect,
    useMemo,
    useLayoutEffect
} from "react";
import { connect } from "react-redux";
import "./index.scss";


function IframePage(props){
    let {
        data,
        userInfo,
        identityList,
        currentIdentity,
        sysAddrInfo
    } = props;
    const [visible, setVisible] = useState(true);
    const identityStr = useMemo(()=>{
        return identityList.map(item=>item.identityCode).join(",");
    }, [identityList]);

    const pageLoad = useCallback(()=>{
        setVisible(false);
    }, []);

    useEffect(()=>{
        return ()=>{
            console.log(sysAddrInfo)
            console.log(data)
            setVisible(true);
        }
    }, [])
    return (
        <Spin spinning={visible} tip="加载中...">
            <iframe className="app-iframe-page" src={
                sysAddrInfo[data.sysId]?.webSvrAddr +
                data.url
                .replace("[token]", sessionStorage.getItem("token"))
                .replace("[identityCode]", currentIdentity.identityCode)
            } onLoad={pageLoad} title="app-iframe"></iframe>
        </Spin>
    )
}
const mapToProps = (state) => {
    return {
        userInfo: state.userInfo,
        identityList: state.identityList,
        sysAddrInfo: state.sysAddrInfo,
        currentIdentity: state.currentIdentity
    }
}
export default connect(mapToProps)(IframePage);